﻿@{
    var KeyId = Tools.HttpHelper.Request.Query["ID"].ToStr();
    KeyId = KeyId.ToGuid() == Guid.Empty ? "" : KeyId;
}
@model List<Sys_Function>
<div id="app">
    <div class="page-content animated fadeInDown">
        <div class="container-fluid pb-100">
            <div class="row" id="form">
                <!--检索面板-->
                @*<div class="col-sm-6">
                        <h4 class="example-title">菜单编号</h4>
                        <input class="form-control" type="text" data-bind="value:Menu_Num" placeholder="A 或者 A-100">
                    </div>

                    <div class="col-sm-6">
                        <h4 class="example-title">菜单名称</h4>
                        <input class="form-control" type="text" data-bind="value:Menu_Name" placeholder="请输入菜单名称">
                    </div>

                    <div class="col-sm-6">
                        <h4 class="example-title">菜单Href</h4>
                        <input class="form-control" type="text" data-bind="value:Menu_Url" placeholder="请输入菜单Href 如：/Admin/User/Index">
                    </div>

                    <div class="col-sm-6">
                        <h4 class="example-title">菜单图标</h4>
                        <input class="form-control" type="text" data-bind="value:Menu_Icon" placeholder="请输入菜单图标 如：fa fa-file">
                    </div>

                    <div class="col-sm-6">
                        <h4 class="example-title">父级菜单</h4>
                        <input class="form-control" type="text" data-bind="value:pname" disabled="disabled">
                    </div>

                    <div class="col-sm-6">
                        <h4 class="example-title">是否显示</h4>
                        <select class="form-control" data-bind="value:Menu_IsShow">
                            <option value="">==是否显示 该菜单==</option>
                            <option value="1">是</option>
                            <option value="2">否</option>
                        </select>
                    </div>*@

                @(UI.Input<Sys_Menu>(item => item.Menu_Num, 6, null, new { placeholder = "A 或者 A-100" }))
                @(UI.Input<Sys_Menu>(item => item.Menu_Name))
                @(UI.Input<Sys_Menu>(item => item.Menu_Url, 6, null, new { placeholder = "请输入菜单Href 如：/Admin/User/Index" }))
                @(UI.Input<Sys_Menu>(item => item.Menu_Icon, 6, null, new { placeholder = "请输入菜单图标 如：fa fa-file" }))
                <div class="col-sm-6">
                    <h4 class="example-title">父级菜单</h4>
                    <input class="form-control" type="text" v-model="pname" disabled="disabled">
                </div>
                @{
                    var _Select_Menu_IsShow = UI.Select<Sys_Menu>(item => item.Menu_IsShow, () =>
                    {
                        var _Html = "";
                        _Html += "<option value=\"1\">是</option>";
                        _Html += "<option value=\"2\">否</option>";
                        return _Html;
                    });
                }
                @_Select_Menu_IsShow

                <div class="col-sm-12">
                    <h4 class="example-title">菜单权限</h4>
                    <div class="row">
                        @foreach (var item in Model)
                        {
                            <div class="col-sm-3">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="Function_ID" value="@item.Function_ID"> @item.Function_Name
                                    </label>
                                </div>
                            </div>
                        }
                    </div>
                </div>


            </div>

        </div>
    </div>
    <!--按钮-->
    <div class="my-ButtonBar text-right">
        <button type="button" class="btn btn-success" v-show="form__KeyId" onclick="adminForm.resetUrl(null)">新增</button>
        <button class="btn btn-primary" v-on:click="save">提交</button>
        <button class="btn btn-danger" onclick="admin.layer.close(admin.getLayerIframeIndex());">关闭</button>
    </div>
</div>
@section css{
    <link href="~/Admin/libs/icheck/skins/all.css" rel="stylesheet" />
}
@section js{
    <script src="~/Admin/js/admin-form.js"></script>
    <script src="~/Admin/libs/icheck/icheck.min.js"></script>

    <!--业务代码-->
    <script type="text/javascript">
        var vueApp = new Vue({
            el: "#app",
            data: {
                form__KeyId: '@KeyId',
                pId: admin.getQueryString("pId"),
                @(UI.CreateViewModel(new Sys_Menu(), "pname", "Sys_Function_List"))
            },
            //页面加载完成
            mounted: function () {
                this.load();
            },
            //函数集合
            methods: {
                load: function () {
                    $('input[type=checkbox]').iCheck({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green'
                    });

                    //获取表单数据
                    console.log(this);
                    adminForm.load({
                        KeyId: this.form__KeyId,
                        url: "@Url.Action("LoadForm")",
                        callBack: function (r) {
                            for (var i = 0; i < r.Menu_Power.length; i++) {
                                $("input[value=" + r.Menu_Power[i] + "]").iCheck('check');
                            }

                            if (vueApp.pId) {
                                admin.ajax({
                                    url: "@Url.Action("LoadForm")",
                                    data: { ID: vueApp.pId },
                                    success: function (r) {
                                        if (!vueApp.form__KeyId) {
                                            vueApp.pname = r.Menu_Name;
                                            vueApp.Menu_ParentID = vueApp.pId;
                                        }
                                    }
                                });
                            } else {
                                vueApp.pname = "一级菜单";

                            }

                            if (!vueApp.form__KeyId) {
                                vueApp.Menu_IsShow = 1;
                            }
                        }
                    });

                },
                //保存
                save: function () {
                    //组装 checkbox
                    var json = [];
                    $.each($("input[name=Function_ID]"), function (i, e) {
                        if ($(this).prop("checked")) {
                            json.push({
                                Function_ID: $(this).val()
                            });
                        }
                    });
                    this.Sys_Function_List = JSON.stringify(json);

                    adminForm.Save({
                        url: "@Url.Action("Save")",
                        callBack: function (r) { }
                    });
                },
                //查找带回
                findBack: function (row, tag, dom) {
                    //if (row != null && row.length > 0) row = row[0];
                    //if (tag == "Role") {
                    //    this.Role_ID = (row ? row._ukid : "");
                    //    this.Role_Name = (row ? row.Role_Name : "");
                    //}
                }

            }
        });
    </script>


}
